package com.example.easy.Controller;


import com.example.easy.Dto.Visitor;
import com.example.easy.Service.myservice.VisitorServise;
import com.example.easy.Tools.ResultCode;

import com.example.easy.mapper.VisitorMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Scope("prototype")
@RestController
@Api(value = "Visitor", description = "游客管理")
@RequestMapping(value = "/visitor")

public class VisitorController {


    @Autowired
    VisitorServise visiorServise;

    @Autowired
    VisitorMapper visiorMapper;

    @ApiOperation(value = "注册", notes = "注册")
    @RequestMapping(value = "/visitorregister", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object regsiter(@RequestBody Visitor visitor) throws IOException {

        return ResultCode.SUCCESS.result(visiorServise.regsiter(visitor));

    }

    @ApiOperation(value = "登入", notes = "登入")
    @RequestMapping(value = "/visitorlogin", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object login(@RequestParam String username, @RequestParam String psd) throws IOException {

        return ResultCode.SUCCESS.result(visiorServise.login(username, psd));

    }

    @ApiOperation(value = "查看", notes = "查看")
    @RequestMapping(value = "/visitorselestuserinf", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object selestuserinf(@RequestParam String username) throws IOException {

        return ResultCode.SUCCESS.result(visiorServise.selestuserinf(username));

    }

    @ApiOperation(value = "修改", notes = "修改")
    @RequestMapping(value = "/visitorupdate", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object update(@RequestBody Visitor visitor) throws IOException {

        return ResultCode.SUCCESS.result(visiorServise.update(visitor));

    }

    @ApiOperation(value = "删除", notes = "删除")
    @RequestMapping(value = "/visitordelete", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object delete(@RequestParam String username) throws IOException {

        return ResultCode.SUCCESS.result(visiorServise.delete(username));

    }




    @ApiOperation(value = "测试", notes = "测试")
    @RequestMapping(value = "/visiortest", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public Object test(@RequestParam String username) throws IOException {

        return ResultCode.SUCCESS.result(visiorMapper.selectall(username));

    }

}
